# -*- coding: UTF-8 -*-
from flask import Flask,redirect, url_for,flash,jsonify
from flask import render_template
from flask import request
import requests
import time
import json
import random

app = Flask(__name__)

#http://127.0.0.1:5000/
@app.route('/')
def Poweron():
    return render_template('index.html')


#http://127.0.0.1:5000/login
@app.route('/login')
def Login():
    return render_template('login.html')
    #return "用户界面"

#http://127.0.0.1:5000/logindata
@app.route('/logindata')
def Logindata():
    logindata_tmp = {"name": "浙江石化"}
    return jsonify(logindata_tmp)

#http://127.0.0.1:5000/logincheck
@app.route('/logincheck',methods=['POST'])
def Logincheck():
    return redirect("/home")

#http://127.0.0.1:5000/home
@app.route('/home')
def Home():
    return render_template('Home.html')
    #return "主界面"


#http://127.0.0.1:5000/corrosion/workstatus
@app.route('/corrosion/workstatus')
def CorrosionWorkstatus():
    return render_template('corrosionworkstatus.html')
    #return "局部腐蚀监控工作状态"

#http://127.0.0.1:5000/corrosion/workstatusdata
@app.route('/corrosion/workstatusdata')
def CorrosionWorkstatusdata():
    workstatusdata_tmp = {
                    "CM1": {"status":"green","number":"1"},
                    "CM2": {"status":"green","number":"2"},
                    "CM3": {"status":"grey","number":"0"},
                    "CM4": {"status":"grey","number":"0"},
                    "CM5": {"status":"grey","number":"0"},
                    "CM6": {"status":"grey","number":"0"},
                    "CM7": {"status":"grey","number":"0"},
                    "CM8": {"status":"grey","number":"0"},
                    "CM9": {"status":"grey","number":"0"},
                    "CM10": {"status":"grey","number":"0"},
                    "CM11": {"status":"grey","number":"0"},
                    "CM12": {"status":"grey","number":"0"},
                    "CM13": {"status":"grey","number":"0"},
                    "CM14": {"status":"grey","number":"0"},
                    "CM15": {"status":"grey","number":"0"},
                    "CM16": {"status":"grey","number":"0"},
                    "CM17": {"status":"grey","number":"0"},
                    "CM18": {"status":"grey","number":"0"},
                    "CM19": {"status":"grey","number":"0"},
                    "CM20": {"status":"grey","number":"0"},
                    "CM21": {"status":"grey","number":"0"},
                    "CM22": {"status":"grey","number":"0"},
                    "CM23": {"status":"grey","number":"0"},
                    "CM24": {"status":"grey","number":"0"},
                    "CM25": {"status":"grey","number":"0"},
                    "CM26": {"status":"grey","number":"0"},
                    "CM27": {"status":"grey","number":"0"},
                    "CM28": {"status":"grey","number":"0"},
                    "CM29": {"status":"grey","number":"0"},
                    "CM30": {"status":"grey","number":"0"},
                    "CM31": {"status":"grey","number":"0"},
                    "CM32": {"status":"grey","number":"0"}
                    }
    return jsonify(workstatusdata_tmp)

#http://127.0.0.1:5000/corrosion/workstatusremarks
@app.route('/corrosion/workstatusremarks')
def CorrosionWorkstatusremarks():
    workstatusremarks_tmp = {
        "CM1": {"Cname": "常压转油线", "Ename": "ZJSHCM1"},
        "CM2": {"Cname": "减压塔底", "Ename": "ZJSHCM2"},
        "CM3": {"Cname": "常压转油线", "Ename": "ZJSHCM3"},
        "CM4": {"Cname": "常压转油线", "Ename": "ZJSHCM4"},
        "CM5": {"Cname": "减压塔底", "Ename": "ZJSHCM5"},
                    }
    return jsonify(workstatusremarks_tmp)

#http://127.0.0.1:5000/corrosion/check/<int>
@app.route('/corrosion/check/<int:id>')
def CorrosionCheck(id):
    # return render_template('Homepage.html')
    return "局部腐蚀监控系统"

#http://127.0.0.1:5000/corrosion/checkdatashow/<int>
@app.route('/corrosion/checkdatashow/<int:id>')
def CorrosionCheckdatashow(id):
    checkdatashow_tmp={
        "number": "CM2",
        "Cname": "常压转油线",
        "Ename": "ZJSHCM2",
        "equipmentnumber": "2",
        "warn": "20",
        "data":[
        {"time": "2015-12-25 14:08:45", "MCR1": "50", "ACR1": "50", "CFR1": "50", "MCD1": "16", "ACD1": "16",
         "CFD1": "50", "E1": "4.99", "I_avg1": "4999.9", "CPEM1": "149.9", "MCR2": "50", "ACR2": "50", "CFR2": "50",
         "MCD2": "16", "ACD2": "16", "CFD2": "50", "E2": "4.99", "I_avg2": "4999.9", "CPEM2": "149.9"},
        {"time": "2015-12-25 14:07:45", "MCR1": "51", "ACR1": "51", "CFR1": "51", "MCD1": "16.1", "ACD1": "16.1",
         "CFD1": "51", "E1": "5.99", "I_avg1": "5999.9", "CPEM1": "159.9", "MCR2": "50", "ACR2": "50", "CFR2": "50",
         "MCD2": "16", "ACD2": "16", "CFD2": "50", "E2": "4.99", "I_avg2": "4999.9", "CPEM2": "149.9"}

    ]
    }
    return jsonify(checkdatashow_tmp)

#http://127.0.0.1:5000/corrosion/checkdataquery
@app.route('/corrosion/checkdataquery',methods=['POST'])
def CorrosionCheckdataquery():
    checkdatashow_tmp = {
        "number": "CM2",
        "Cname": "常压转油线",
        "Ename": "ZJSHCM2",
        "equipmentnumber": "2",
        "warn": "20",
                "data":[
        {"time": "2015-12-25 14:08:45", "MCR1": "50", "ACR1": "50", "CFR1": "50", "MCD1": "16", "ACD1": "16",
         "CFD1": "50", "E1": "4.99", "I_avg1": "4999.9", "CPEM1": "149.9", "MCR2": "50", "ACR2": "50", "CFR2": "50",
         "MCD2": "16", "ACD2": "16", "CFD2": "50", "E2": "4.99", "I_avg2": "4999.9", "CPEM2": "149.9"},
        {"time": "2015-12-25 14:07:45", "MCR1": "51", "ACR1": "51", "CFR1": "51", "MCD1": "16.1", "ACD1": "16.1",
         "CFD1": "51", "E1": "5.99", "I_avg1": "5999.9", "CPEM1": "159.9", "MCR2": "50", "ACR2": "50", "CFR2": "50",
         "MCD2": "16", "ACD2": "16", "CFD2": "50", "E2": "4.99", "I_avg2": "4999.9", "CPEM2": "149.9"}

    ]
    }
    return jsonify(checkdatashow_tmp)

##http://127.0.0.1:5000/corrosion/checkdataanalyse
@app.route('/corrosion/checkdataanalyse')
def CorrosionCheckdataanalyse():
    #return render_template('Showobject.html')
    return "在线腐蚀检测系统数据分析"

#http://127.0.0.1:5000/corrosion/checkdatatmp
@app.route('/corrosion/checkdatatmp')
def CorrosionCheckdatatmp():
    #return render_template('Showobject.html')
    return "导入数据腐蚀监测系统曲线分析"

#http://127.0.0.1:5000/corrosion/workstatusdatatmp
@app.route('/corrosion/workstatusdatatmp')
def CorrosionWorkstatusdataTmp():
    workstatusdata_tmp = {
                    "CM1": {"status":"green","number":"1"},
                    "CM2": {"status":"green","number":"2"},
                    "CM3": {"status":"grey","number":"0"},
                    "CM4": {"status":"grey","number":"0"},
                    "CM5": {"status":"grey","number":"0"},
                    "CM6": {"status":"grey","number":"0"},
                    "CM7": {"status":"grey","number":"0"},
                    "CM8": {"status":"grey","number":"0"},
                    "CM9": {"status":"grey","number":"0"},
                    "CM10": {"status":"grey","number":"0"},
                    "CM11": {"status":"grey","number":"0"},
                    "CM12": {"status":"grey","number":"0"},
                    "CM13": {"status":"grey","number":"0"},
                    "CM14": {"status":"grey","number":"0"},
                    "CM15": {"status":"grey","number":"0"},
                    "CM16": {"status":"grey","number":"0"},
                    "CM17": {"status":"grey","number":"0"},
                    "CM18": {"status":"grey","number":"0"},
                    "CM19": {"status":"grey","number":"0"},
                    "CM20": {"status":"grey","number":"0"},
                    "CM21": {"status":"grey","number":"0"},
                    "CM22": {"status":"grey","number":"0"},
                    "CM23": {"status":"grey","number":"0"},
                    "CM24": {"status":"grey","number":"0"},
                    "CM25": {"status":"grey","number":"0"},
                    "CM26": {"status":"grey","number":"0"},
                    "CM27": {"status":"grey","number":"0"},
                    "CM28": {"status":"grey","number":"0"},
                    "CM29": {"status":"grey","number":"0"},
                    "CM30": {"status":"grey","number":"0"},
                    "CM31": {"status":"grey","number":"0"},
                    "CM32": {"status":"grey","number":"0"}
                    }
    return jsonify(workstatusdata_tmp)

#http://127.0.0.1:5000/corrosion/checkdataquerytmp
@app.route('/corrosion/checkdataquerytmp',methods=['POST'])
def CorrosionCheckdataquerytmp():
    checkdatashow_tmp = {
        "number": "CM2",
        "Cname": "常压转油线",
        "Ename": "ZJSHCM2",
        "equipmentnumber": "2",
        "warn": "20",
                "data":[
        {"time": "2015-12-25 14:08:45", "MCR1": "50", "ACR1": "50", "CFR1": "50", "MCD1": "16", "ACD1": "16",
         "CFD1": "50", "E1": "4.99", "I_avg1": "4999.9", "CPEM1": "149.9", "MCR2": "50", "ACR2": "50", "CFR2": "50",
         "MCD2": "16", "ACD2": "16", "CFD2": "50", "E2": "4.99", "I_avg2": "4999.9", "CPEM2": "149.9"},
        {"time": "2015-12-25 14:07:45", "MCR1": "51", "ACR1": "51", "CFR1": "51", "MCD1": "16.1", "ACD1": "16.1",
         "CFD1": "51", "E1": "5.99", "I_avg1": "5999.9", "CPEM1": "159.9", "MCR2": "50", "ACR2": "50", "CFR2": "50",
         "MCD2": "16", "ACD2": "16", "CFD2": "50", "E2": "4.99", "I_avg2": "4999.9", "CPEM2": "149.9"}

    ]
    }
    return jsonify(checkdatashow_tmp)

if __name__ == '__main__':
   app.run(debug = True)